package leetcodecompetition.D353;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @Author: Siantar
 * @Date: 2023-07-09-11:10
 * @Description: 1.0
 */
public class T6912 {
    public int maxNonDecreasingLength(int[] nums1, int[] nums2) {
        int n = nums1.length;
        int[][] dp = new int[n][2];
        for (int i = 0; i < n; i++) {
            Arrays.fill(dp[i],1);
        }
        int res = 1;
        for (int i = 1; i < n; i++) {
            if (nums1[i] > nums1[i - 1]) {
                dp[i][0] = Math.max(dp[i][0],dp[i - 1][0] + 1)  ;
            }
            if (nums1[i] > nums2[i - 1]) {
                dp[i][0] = Math.max(dp[i][0],dp[i - 1][1] + 1);
            }
            if (nums2[i] > nums1[i - 1]) {
                dp[i][1] = Math.max(dp[i][1],dp[i - 1][0] + 1);
            }
            if (nums2[i] > nums2[i - 1]) {
                dp[i][1] = Math.max(dp[i][1], dp[i - 1][1] + 1);
            }
            res = Math.max(res, Math.max(dp[i][0], dp[i][1]));
        }
        return res;
    }
    @Test
    public void test() {
        System.out.println(maxNonDecreasingLength(new int[]{1,4},new int[]{4,9}));
    }
}
